import * as module from "@/tools/util";
import * as Request from '@/api/liubike';
import store from "@/tools/factory"
import { config, isDev } from '@/api/config';

import wx  from '@/tools/wx'
import commonJs from '@/views/commonJs/common'
let that
let loginInfo = null;

/**
 * 转化:   this.data -> this._data
 * ev.detail -> ev.target
 */

export default {
    mixins: [commonJs],
    data() {
        return {
            containerShow: false,
            list: []
        }
    },
    mounted() {
        that = this
        Request.getAuthorizeInfo().then(res => {
            if (res.success) {
                if (res.data.length > 0) {
                    that.setData({
                        containerShow: true,
                        list: res.data
                    })
                } else {
                    that.setData({
                        containerShow: false
                    })
                }
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: "none"
                })
                that.setData({
                    containerShow: false
                })
            }
        }).catch(err => {
            wx.showToast({
                title: `获取授权列表失败`,
                icon: "none"
            })
            that.setData({
                containerShow: false
            })
        })
    },
    methods: {
        onShareAppMessage: function () {
            return {
                title: '小遛共享',
                path: '/index',
            }
        },
        onLoad: function (options) {
            that = this;
        },
        goWx(e) {
            const item = e.currentTarget.dataset.obj;
            store.set("permissionDetail", item)
            wx.navigateTo({url: `/permissionDetail`});
        },
        onShow() {
            Request.getAuthorizeInfo().then(res => {
                if (res.success) {
                    if (res.data.length > 0) {
                        that.setData({
                            containerShow: true,
                            list: res.data
                        })
                    } else {
                        that.setData({
                            containerShow: false
                        })
                    }
                } else {
                    wx.showToast({
                        title: res.msg,
                        icon: "none"
                    })
                    that.setData({
                        containerShow: false
                    })
                }
            }).catch(err => {
                wx.showToast({
                    title: `获取授权列表失败`,
                    icon: "none"
                })
                that.setData({
                    containerShow: false
                })
            })
        }
    }
}
